let http = require("http");
let url = require("url");
let fs = require("fs");

http.createServer((req, res) => {
    let pathname = url.parse(req.url).pathname;
    if (pathname === '/index.html') {
        let data = fs.readFileSync('./index.html').toString();//读取文件内容并转换为字符串
        res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
        res.end(data);
    } else {
        console.log('hello world');
        res.writeHead(200, {'Content-Type': 'text/plain; charset=utf-8'});
        res.end('hello world');
    }
}).listen(8888)

